package com.test.prolenders.dialog_prolenders;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.test.prolenders.R;
import com.test.prolenders.bean_prolenders.config_prolenders.AppShowCustomize_prolenders;
import com.test.prolenders.bean_prolenders.userinfo_prolenders.OthersInfo_prolenders;


public class BindAccountChannelDialog_Fr_prolenders extends Dialog {

    private final String mobile;

    private final Runnable denyRunnable, addAccountRunnable;

    private ImageView logoIv;
    private TextView channelTv,mobileTv;
    private Button denyBtn,addBtn;

    public BindAccountChannelDialog_Fr_prolenders(@NonNull Context context, String mobile, Runnable denyRunnable, Runnable addAccountRunnable) {
        super(context);
        this.mobile = mobile;
        this.denyRunnable = denyRunnable;
        this.addAccountRunnable = addAccountRunnable;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_bind_account_channel_fr_prolenders);

        getWindow().setBackgroundDrawableResource(R.color.transparent_prolenders);
        setCanceledOnTouchOutside(false);
        getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

        logoIv = findViewById(R.id.dbacf_iv_logo);
        channelTv = findViewById(R.id.dbacf_tv_channel);
        mobileTv = findViewById(R.id.dbacf_tv_mobile);
        denyBtn = findViewById(R.id.dbacf_btn_deny);
        addBtn = findViewById(R.id.dbacf_btn_add);

        TextView textTv = findViewById(R.id.dbacf_tv_text);
        textTv.setText(getContext().getString(R.string.bindaccountchannel_fr_text_1_prolenders).replaceAll("xxx", OthersInfo_prolenders.getInstance().getChannel()));

        initView();
    }

    @SuppressLint("SetTextI18n")
    private void initView(){

        String channel = OthersInfo_prolenders.getInstance().getChannel();

        //获取图标
        Bitmap logoBm = AppShowCustomize_prolenders.getInstance().getChannelLogoByValue(channel);
        if (logoBm!=null) logoIv.setImageBitmap(logoBm);

        mobileTv.setText(mobile);
        channelTv.setText(channel);

        denyBtn.setOnClickListener(v -> {
            if (denyRunnable!=null) denyRunnable.run();
            dismiss();
        });

        addBtn.setOnClickListener(v -> {
            if (addAccountRunnable!=null) addAccountRunnable.run();
            dismiss();
        });

    }

}
